package com.relytosoft.mizar.media.camera.services.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.relytosoft.dubhe.common.core.base.page.PageQuery;
import com.relytosoft.dubhe.common.core.object.ResponseResult;
import com.relytosoft.dubhe.common.core.utils.CommonUtils;
import com.relytosoft.dubhe.common.log.annotation.OpLog;
import com.relytosoft.dubhe.common.log.enums.OpTypeEnum;
import com.relytosoft.mizar.media.camera.api.pojo.dto.DownLoadLogDto;
import com.relytosoft.mizar.media.camera.api.pojo.vo.DownLoadLogVo;
import com.relytosoft.mizar.media.camera.services.service.DownLoadLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author wss
 * @version 1.0
 * @date 2022/6/15 15:11
 */
@Api(tags = {"下载日志"})
@RestController
@RequestMapping("downloadLog")
public class DownLoadLogController {

    @Autowired
    private DownLoadLogService downLoadLogService;

    @SaCheckPermission("downloadLog:list")
    @OpLog(msg = "下载日志列表", opType = OpTypeEnum.SELECT)
    @ApiOperation("查询")
    @GetMapping("/pageList")
    public ResponseResult<Map<String, Object>> list(DownLoadLogDto downLoadLogDto, PageQuery pageQuery) {
        IPage<DownLoadLogVo> page = downLoadLogService.pageList(downLoadLogDto, pageQuery);
        return ResponseResult.ok(CommonUtils.getPageData(page));
    }


    @SaCheckPermission("downloadLog:delete")
    @OpLog(msg = "删除日志列表", opType = OpTypeEnum.SELECT)
    @ApiOperation("删除任务")
    @DeleteMapping("/delete/{taskId}")
    public ResponseResult<Void> delete(@PathVariable Integer taskId) {
        if (downLoadLogService.removeById(taskId)) {
            return ResponseResult.ok();
        }
        return ResponseResult.fail();
    }

}
